/*
 * @(#)CompanyDaoImpl.java 创建于 2013年3月14日 
 * 
 * Copyright (c) 2013-2014 by Drow.  
 *
 */
package com.hangxin.basic.dao.impl;


import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.hangxin.basic.dao.CompanyDao;
import com.hangxin.basic.model.Company;
import com.hangxin.commons.dao.impl.BasicDaoImpl;
import com.hangxin.commons.util.PageModel;


@Repository
public class CompanyDaoImpl extends BasicDaoImpl implements CompanyDao
{
	private static final Logger logger = LoggerFactory.getLogger(CompanyDaoImpl.class);



	@Override
	public Map<String, Object> companyFindById(Object[] params) {
		String sql = "select * from company where  id=?";		
		return this.findByMap(sql, params);
	}

	
	@Override
	public List<Map<String, Object>> companyFind() {
		String sql = "select * from company ";		
		return this.findMap(sql);
	}
	public PageModel companyList(PageModel pageModel, Object[] paramscount,
			Object[] params) {
		String sql = "select * from company order by id limit ?,?";
		String sqlcount = "select count(*) from company";
		return this.listByObject(sqlcount, sql, pageModel, paramscount, params);
	}
	
	public void save(Company company) {
		String sql = "insert into company(taxno,speclimit,commlimit,"
				+ "machineno,companyname,addresstel,account,review,payee)"
				+ "values(?,?,?,?,?,?,?,?,?)";
		Object[] params = new Object[]{company.getTaxno(),company.getSpeclimit(),
				company.getCommlimit(),company.getMachineno(),company.getCompanyname(),
				company.getAddresstel(),company.getAccount(),company.getReview(),
				company.getPayee()};
		 this.update(sql, params);
		
	}

	
	public int isExist(String taxno, Long machineno) {
		String sql = "select count(*) from company where taxno=? and machineno=?";
		return this.findByCount(sql,new Object[]{taxno,machineno});
	}

	public void update(Company company) {
		String sql = "update company set companyname=?,speclimit=?,commlimit=?,addresstel=?,account=?,"
				+ "review=?,payee=? where taxno=? and machineno=?";
		Object[] params = new Object[]{company.getCompanyname(),company.getSpeclimit(),
				company.getCommlimit(),company.getAddresstel(),company.getAccount(),
				company.getReview(),company.getPayee(),company.getTaxno(),company.getMachineno()};
		this.update(sql, params);
		
	}
}
